﻿module Claret.Main

open Microsoft.FSharp.Text
open Lexer
open FParsec.CharParsers
open FParsec.Primitives

let () =   
  try 
    let fileName = "test.in"

    // Parse grammar
    let result = runParserOnFile pGrammar () fileName System.Text.Encoding.Default
    // for the moment we just print out the AST
    let output =
        match result with
        | Success (v, _, _) -> List.fold (fun x c -> x + c.ToString() + "\n") "" v
        | Failure (msg, err, _) -> msg
    
    System.IO.File.WriteAllText("test.out", output);
  with 
  | :? System.IO.IOException -> eprintf "Could not read file"
  | x -> eprintf "%A" x // program should terminate correctly. Writing to error stream for Tester